package com.taoyibao.hongcanting.ui.home.activity;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.activity.BaseActivityPresenter;
import com.taoyibao.hongcanting.cache.SpUtils;
import com.taoyibao.hongcanting.constant.CodeConstant;
import com.taoyibao.hongcanting.ui.home.delegate.NumberPeopleDelegate;

/**
 * @author TangAnna
 * @description: 选择就餐人数
 * @date :${DATA} 11:54
 */
public class NumberPeopleActivity extends BaseActivityPresenter<NumberPeopleDelegate> implements View.OnClickListener {

    private String mSource;

    @Override
    protected Class<NumberPeopleDelegate> getDelegateClass() {
        return NumberPeopleDelegate.class;
    }

    /**
     * @param context
     * @param source
     */
    public static void open(Context context, String source) {
        Intent intent = new Intent(context, NumberPeopleActivity.class);
        intent.putExtra(CodeConstant.ACTIVITY_SOURCE, source);
        context.startActivity(intent);
    }

    @Override
    protected void bindEvenListener() {
        super.bindEvenListener();
        mSource = getIntent().getStringExtra(CodeConstant.ACTIVITY_SOURCE);
        viewDelegate.get(R.id.btn_number_confirm).setOnClickListener(this);
        viewDelegate.setAmountData(12);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_number_confirm://点击确定
                if (viewDelegate.getSelectAmount() != 0) {
                    SpUtils.putUserNub(viewDelegate.getSelectAmount());
                    if (TextUtils.equals(mSource, CodeConstant.ACTIVITY_SOURCE_HOME)) {//来源于首页
                        MenuActivity.open(this);
                    } else {//来源于提交订单
                        finish();
                    }
                }
                break;
        }
    }
}
